package zisu.netty.practice.netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author: 蔡翔
 * @Date: 2020/7/12 20:52
 * @Version 1.0
 */
public class TestServer {
    public static void main(String[] args) {
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class).childHandler(new TestServerInitializer());
            //加入sync() 就 相当于 get() 这个任务是完成的。
            ChannelFuture channelFuture = serverBootstrap.bind(6688).sync();
            //监控 HttpServer 当这个channel 关闭的时候执行的方法，加了sync() 说明程序到这一步 就会阻塞在这里等待 channel关闭 事件触发
            channelFuture.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
